$(function () {
    var start = {
        elem: '#startTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        istime: true,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    }
    var end = {
        elem: '#endTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        istime: true,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    }
    laydate(start);
    laydate(end);

    queryGainAttendRecordList(1);
    $('body').on('click','#btn1,#btn2', function () {
        queryGainAttendRecordList(1);
    }).on('click','#cash-withdrawal',function () {//申请提现
        var status = check();
        if(status==true){
            commonCash(2);
        }
    }).on('click','.openInfo',function(){
        var questionId = $(this).data("id");
        parent.layer.open({
            type: 2,
            shadeClose: false,
            area:winArea,
            skin: 'layui-layer-demo',
            title: '收益明细',
            content: baseloaction+"/admin/qa/record/queryGainAttendList?type=1&questionId="+questionId
        });
    });

    function queryGainAttendRecordList(pageNo) {
        var params = $("#search-form").serializeJSON();
        params.type=typeTo;
        if(questionId!=null&&questionId!=0&&questionId!=''&&typeTo=="1"){
            params.questionIds=questionId;
        }
        params = JSON.stringify(params);
        var obj = {
            url: baseloaction + '/admin/qa/record/ajaxQueryGainAttendList',//请求URLt
            contextId: 'gain-attend-list-context',//响应内容页面设置内容ID
            params: params,//请求参数
            pageNo: pageNo,//页码
            pageCall: queryGainAttendRecordList, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
            callback: function (pageNo) {//数据加载完成回调
                $("#count").html("(共"+ total +"条收益记录)");
            }
        };
        ajaxGetListData(obj);
    }

    /**
     * 难是否有可以结算的旁听分成收益
     * @returns {boolean}
     */
    function check() {
        var status = false;
        $.ajax({
            url:baseloaction +'/admin/qa/record/getGainAttenRecordCount',
            type:'post',
            dataType:'json',
            async:false,
            success:function (result) {
                if(result.success==true){
                    status = true;
                }else{
                    icModale(0,result.message);
                }
            },
            error:function (error) {
                icModale(0,'系统错误，申请结算失败');
            }
        });
        return status;
    }
});